// 导入变量
@import './variables.scss';

// 清除浮动
@mixin clearfix {
  &::after {
    content: '';
    display: table;
    clear: both;
  }
}

// 文本省略
@mixin ellipsis($lines: 1) {
  @if $lines == 1 {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  } @else {
    display: -webkit-box;
    -webkit-line-clamp: $lines;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

// 绝对居中
@mixin center($position: absolute) {
  position: $position;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

// Flex居中
@mixin flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

// Flex布局
@mixin flex($direction: row, $wrap: nowrap, $justify: flex-start, $align: stretch) {
  display: flex;
  flex-direction: $direction;
  flex-wrap: $wrap;
  justify-content: $justify;
  align-items: $align;
}

// 响应式断点
@mixin respond-to($breakpoint) {
  @if $breakpoint == xs {
    @media (max-width: #{$breakpoint-sm - 1px}) {
      @content;
    }
  }
  @if $breakpoint == sm {
    @media (min-width: #{$breakpoint-sm}) {
      @content;
    }
  }
  @if $breakpoint == md {
    @media (min-width: #{$breakpoint-md}) {
      @content;
    }
  }
  @if $breakpoint == lg {
    @media (min-width: #{$breakpoint-lg}) {
      @content;
    }
  }
  @if $breakpoint == xl {
    @media (min-width: #{$breakpoint-xl}) {
      @content;
    }
  }
  @if $breakpoint == 2xl {
    @media (min-width: #{$breakpoint-2xl}) {
      @content;
    }
  }
}

// 自定义断点
@mixin respond-above($size) {
  @media (min-width: $size) {
    @content;
  }
}

@mixin respond-below($size) {
  @media (max-width: $size - 1px) {
    @content;
  }
}

@mixin respond-between($min, $max) {
  @media (min-width: $min) and (max-width: $max - 1px) {
    @content;
  }
}

// 按钮样式
@mixin button-variant($color, $background, $border: $background) {
  color: $color;
  background-color: $background;
  border-color: $border;

  &:hover,
  &:focus {
    color: $color;
    background-color: darken($background, 7.5%);
    border-color: darken($border, 10%);
  }

  &:active {
    color: $color;
    background-color: darken($background, 10%);
    border-color: darken($border, 12.5%);
  }

  &:disabled,
  &.disabled {
    color: $color;
    background-color: $background;
    border-color: $border;
    opacity: 0.65;
  }
}

// 按钮大小
@mixin button-size($padding-y, $padding-x, $font-size, $line-height, $border-radius) {
  padding: $padding-y $padding-x;
  font-size: $font-size;
  line-height: $line-height;
  border-radius: $border-radius;
}

// 输入框样式
@mixin input-variant($border-color, $focus-border-color, $focus-box-shadow) {
  border-color: $border-color;

  &:focus {
    border-color: $focus-border-color;
    outline: 0;
    box-shadow: $focus-box-shadow;
  }
}

// 卡片样式
@mixin card($padding: $card-padding, $margin: $card-margin, $border-radius: $card-border-radius, $shadow: $card-shadow) {
  background: $card-background;
  padding: $padding;
  margin: $margin;
  border-radius: $border-radius;
  box-shadow: $shadow;
}

// 渐变背景
@mixin gradient($start-color, $end-color, $direction: to bottom) {
  background: $start-color;
  background: linear-gradient($direction, $start-color, $end-color);
}

// 过渡
@mixin transition($property: all, $duration: $transition-duration-base, $timing-function: $transition-timing-function-ease, $delay: 0s) {
  transition: $property $duration $timing-function $delay;
}

// 变换
@mixin transform($transforms) {
  transform: $transforms;
}

// 旋转
@mixin rotate($degrees) {
  transform: rotate(#{$degrees}deg);
}

// 缩放
@mixin scale($scale) {
  transform: scale($scale);
}

// 平移
@mixin translate($x, $y) {
  transform: translate($x, $y);
}

// 阴影
@mixin box-shadow($shadow) {
  box-shadow: $shadow;
}

// 边框
@mixin border($width: 1px, $style: solid, $color: $border-color) {
  border: $width $style $color;
}

// 圆角
@mixin border-radius($radius) {
  border-radius: $radius;
}

// 字体
@mixin font($size: $font-size-base, $weight: $font-weight-normal, $line-height: $line-height-base, $family: $font-family-base) {
  font-size: $size;
  font-weight: $weight;
  line-height: $line-height;
  font-family: $family;
}

// 文本颜色
@mixin text-color($color) {
  color: $color;
}

// 背景颜色
@mixin bg-color($color) {
  background-color: $color;
}

// 尺寸
@mixin size($width, $height: $width) {
  width: $width;
  height: $height;
}

// 最小尺寸
@mixin min-size($width, $height: $width) {
  min-width: $width;
  min-height: $height;
}

// 最大尺寸
@mixin max-size($width, $height: $width) {
  max-width: $width;
  max-height: $height;
}

// 定位
@mixin position($position, $top: null, $right: null, $bottom: null, $left: null) {
  position: $position;
  top: $top;
  right: $right;
  bottom: $bottom;
  left: $left;
}

// 绝对定位
@mixin absolute($top: null, $right: null, $bottom: null, $left: null) {
  @include position(absolute, $top, $right, $bottom, $left);
}

// 相对定位
@mixin relative($top: null, $right: null, $bottom: null, $left: null) {
  @include position(relative, $top, $right, $bottom, $left);
}

// 固定定位
@mixin fixed($top: null, $right: null, $bottom: null, $left: null) {
  @include position(fixed, $top, $right, $bottom, $left);
}

// 粘性定位
@mixin sticky($top: null, $right: null, $bottom: null, $left: null) {
  @include position(sticky, $top, $right, $bottom, $left);
}

// 层级
@mixin z-index($index) {
  z-index: $index;
}

// 透明度
@mixin opacity($opacity) {
  opacity: $opacity;
}

// 可见性
@mixin visibility($visibility) {
  visibility: $visibility;
}

// 显示/隐藏
@mixin show {
  display: block !important;
}

@mixin hide {
  display: none !important;
}

// 滚动条样式
@mixin scrollbar($width: 6px, $track-color: transparent, $thumb-color: rgba(0, 0, 0, 0.3), $thumb-hover-color: rgba(0, 0, 0, 0.5)) {
  &::-webkit-scrollbar {
    width: $width;
    height: $width;
  }

  &::-webkit-scrollbar-track {
    background: $track-color;
  }

  &::-webkit-scrollbar-thumb {
    background: $thumb-color;
    border-radius: $width / 2;

    &:hover {
      background: $thumb-hover-color;
    }
  }
}

// 1px边框解决方案
@mixin hairline($direction: all, $color: $border-color, $radius: 0) {
  position: relative;

  &::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 200%;
    height: 200%;
    transform: scale(0.5);
    transform-origin: 0 0;
    pointer-events: none;
    box-sizing: border-box;
    border: 0 solid $color;
    border-radius: $radius * 2;

    @if $direction == all {
      border-width: 1px;
    } @else if $direction == top {
      border-top-width: 1px;
    } @else if $direction == right {
      border-right-width: 1px;
    } @else if $direction == bottom {
      border-bottom-width: 1px;
    } @else if $direction == left {
      border-left-width: 1px;
    } @else if $direction == horizontal {
      border-left-width: 1px;
      border-right-width: 1px;
    } @else if $direction == vertical {
      border-top-width: 1px;
      border-bottom-width: 1px;
    }
  }
}

// 安全区域适配
@mixin safe-area-inset($property, $direction) {
  #{$property}: constant(safe-area-inset-#{$direction});
  #{$property}: env(safe-area-inset-#{$direction});
}

// 底部安全区域
@mixin safe-area-bottom($property: padding-bottom) {
  @include safe-area-inset($property, bottom);
}

// 顶部安全区域
@mixin safe-area-top($property: padding-top) {
  @include safe-area-inset($property, top);
}

// 左侧安全区域
@mixin safe-area-left($property: padding-left) {
  @include safe-area-inset($property, left);
}

// 右侧安全区域
@mixin safe-area-right($property: padding-right) {
  @include safe-area-inset($property, right);
}

// 深色模式适配
@mixin dark-mode {
  @media (prefers-color-scheme: dark) {
    @content;
  }
}

// 高对比度模式
@mixin high-contrast {
  @media (prefers-contrast: high) {
    @content;
  }
}

// 减少动画
@mixin reduce-motion {
  @media (prefers-reduced-motion: reduce) {
    @content;
  }
}

// 触摸设备
@mixin touch-device {
  @media (hover: none) and (pointer: coarse) {
    @content;
  }
}

// 鼠标设备
@mixin mouse-device {
  @media (hover: hover) and (pointer: fine) {
    @content;
  }
}

// 视网膜屏幕
@mixin retina {
  @media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    @content;
  }
}

// 横屏
@mixin landscape {
  @media (orientation: landscape) {
    @content;
  }
}

// 竖屏
@mixin portrait {
  @media (orientation: portrait) {
    @content;
  }
}

// 打印样式
@mixin print {
  @media print {
    @content;
  }
}

// 无障碍辅助
@mixin sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

// 取消无障碍隐藏
@mixin sr-only-focusable {
  &:active,
  &:focus {
    position: static !important;
    width: auto !important;
    height: auto !important;
    padding: inherit !important;
    margin: inherit !important;
    overflow: visible !important;
    clip: auto !important;
    white-space: inherit !important;
  }
}

// 加载动画
@mixin loading-spinner($size: $loading-spinner-size, $color: $loading-spinner-color, $border-width: 2px) {
  display: inline-block;
  width: $size;
  height: $size;
  border: $border-width solid rgba($color, 0.3);
  border-radius: 50%;
  border-top-color: $color;
  animation: spin 1s ease-in-out infinite;
}

// 基础动画关键帧
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fade-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

@keyframes slide-in-up {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes slide-in-down {
  from {
    transform: translateY(-20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes slide-in-left {
  from {
    transform: translateX(20px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slide-in-right {
  from {
    transform: translateX(-20px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes zoom-in {
  from {
    transform: scale(0.8);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes bounce {
  0%, 20%, 53%, 80%, 100% {
    transform: translateY(0);
  }
  40%, 43% {
    transform: translateY(-20px);
  }
  70% {
    transform: translateY(-10px);
  }
  90% {
    transform: translateY(-5px);
  }
}

@keyframes shake {
  0%, 100% {
    transform: translateX(0);
  }
  10%, 30%, 50%, 70%, 90% {
    transform: translateX(-10px);
  }
  20%, 40%, 60%, 80% {
    transform: translateX(10px);
  }
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(66, 153, 225, 0.7);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(66, 153, 225, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(66, 153, 225, 0);
  }
}